def general(n):
    counter = 0
    for i in range(2, n):
        if n % i == 0:
            counter = counter + 1
    if counter>0:
        return 0
    else:
        return n

n=int(input())
n1 = n//1000
n2 = n//100%10
n3 = n//10%10
n4 = n%10
h = 0



if 999<n<10000:
    u = n1
    g = general(u)
    if g>h:
        h=g
    u = n2
    g = general(u)
    if g>h:
        h=g
    u = n3
    g = general(u)
    if g>h:
        h=g
    u = n4
    g = general(u)
    if g>h:
        h=g
    u = n1*10 + n2
    g = general(u)
    if g>h:
        h=g
    u = n2*10 + n3
    g = general(u)
    if g>h:
        h=g
    u = n3*10 + n4
    g = general(u)
    if g>h:
        h=g
    u = n1*100 + n2*10 + n3
    g = general(u)
    if g>h:
        h=g
    u = n2*100 + n3*10 +n4
    g = general(u)
    if g>h:
        h=g
    u=n
    g = general(u)
    if g>h:
        h=g
print(h) 
    
    
        
